// packageA/mycomponent/goodsComponent/plugin/comment/comment.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goodsInfo: {
      type: null,
      observer: function (newValue) {
        this.setData({
          goodsInfo: newValue,
        });
        if (newValue.get_comment) {
          let getComment = newValue.get_comment;
          this.setData({
            commentLimit: getComment.data ? getComment.data.slice(0, 5) : [],
            is_show_default_praise: getComment.is_show_good_reputation_text
          })
        }
      }
    },
    goodsId: {
      type: null
    },
    commentPage: {
      type: null
    },
    comment_name: {
      type: null,
      value:"精选口碑"
    },
    goods_type:{
      type:null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    commentLimit: [], //设置最新5条评论
    streetShow: false,
    is_show_default_praise: 0,
  },
  lifetimes: {
    attached(e) {
      // let data = this.data.goodsInfo;
      // if (data.get_comment) {
      //   this.setData({
      //     commentLimit: data.get_comment.data ? data.get_comment.data.slice(0, 5) : [],
      //   });
      // }

    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goKb() {
      console.log(this.data.goodsInfo)
      wx.navigateTo({
        url: '/packageA/others/GoodsComment/GoodsComment?gid=' + this.data.goodsId + '&istype=comment' + `&comment_name=${this.data.goods_type == 'course'?'课程评论':''}`,
      });
    },
    //跳转评论详情
    toContentInfo(e) {
      let jsondata = e.currentTarget.dataset.jsondata;
      wx.navigateTo({
        url: "/packageD/member/CommentDetails/CommentDetails?order_id=" + jsondata.order_id + "&goods_id=" + jsondata.goods_id + "&uid=" + jsondata.uid + "&comment_id=" + jsondata.id,
      });
    },
    //查看大图
    seePicture(evt) {
      let pics = evt.currentTarget.dataset.pics;
      let index = evt.currentTarget.dataset.index;
      wx.previewImage({
        current: pics[index], // 当前显示图片的http链接
        urls: pics, // 需要预览的图片http链接列表
      });
    },
    streetClose() {
      this.setData({
        streetShow: false,
      });
    },
    //获取评论数据
    getCommentData() {
      let that = this;
      let urlStr = app.getNetAddresss("goods.comment.get-comment");
      urlStr += "&goods_id=" + this.data.goodsId;
      urlStr += "&page=" + this.data.commentPage;
      app._getNetWork({
        showToastIn: false,
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.data.length < 20) {
              that.setData({
                noMoreComment: true,
              });
            }
            that.setData({
              commentPage: that.data.commentPage + 1,
            });
            if (!that.data.third_content) {
              that.setData({
                third_content: [],
              });
            }
            that.setData({
              third_content: [...that.data.third_content, ...res.data.data],
              streetShow: true
            });
            if (app._isTextEmpty(that.data.third_content)) {
              // console.log("空没评论");
              that.setData({
                thirKong: false,
              });
            } else {
              // console.log("不空");
              that.setData({
                thirKong: true,
              });
            }
          } else {
            that.setData({
              is_third_content: false,
            });
          }
        },
        fail: function (res) {
          that.setData({
            is_third_content: false,
          });
          console.log(res);
        },
      });
    },
  }
});